package com.xinqi.common.base.utils.chars;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Pattern;

/**
 * 字符串匹配
 *
 * @author linkai
 * @date 2023/2/21
 */
public interface Patterns {
    Pattern PHONE_PATTERN = Pattern.compile("^1\\d{10}$");
    Pattern MAIL_PATTERN = Pattern.compile("^(.+)@(\\S+)$");

    static boolean matcher(Pattern p, String s) {
        if (StringUtils.isBlank(s)) {
            return false;
        }
        return p.matcher(s).matches();
    }

    static boolean mail(String s) {
        return matcher(MAIL_PATTERN, s);
    }

    static boolean phone(String s) {
        return matcher(PHONE_PATTERN, s);
    }
}
